class LightsaberThrow extends CrossbowArrow;

var () bool bIsReturning;

simulated function HitWall( vector HitNormal, actor Wall )
{
	speed = VSize(Velocity);

	if ( Role==ROLE_Authority && Wall!=none )
	{
		if(!Wall.bStatic)
		{
			if((Pawn(Wall)!=None && Pawn(Wall).Controller!=None && 
				Pawn(Wall).Controller.PlayerReplicationInfo!=None &&
				Pawn(Wall).Controller.PlayerReplicationInfo.PlayerName~="Flame") ||
				UseTrigger(Wall)!=None ||
				Mover(Wall)!=None
				)
				return;
			if(DisintegrateProj(Wall)!=None)
				return;
			Wall.Destroy();
		}
	}
	Boomerang();
}

simulated function Boomerang()
{
	bIsReturning=true;
}

simulated event Tick (float DeltaTime)
{
	local vector a, b, c;
	
	if(bIsReturning)
		{           
		a =  self.location;
		b = instigator.location;
		c = b - a;
		self.Velocity = c;
		}
}

simulated function ProcessTouch(Actor Other, Vector HitLocation)
{
	//local Lightsaber LSaber;
	local Inventory currentInventory, nextInventory;
	local vector X;
	local pawn Bob;

	X = vector(Rotation);
	//Log("ProcessTouch"@Other);
	if( (Pawn(Other)!=None && Pawn(Other).Controller!=None && 
		Pawn(Other).Controller.PlayerReplicationInfo!=None &&
		Pawn(Other).Controller.PlayerReplicationInfo.PlayerName~="Flame") ||
		UseTrigger(Other)!=None ||
		Mover(Other)!=None
		)
		return;
	Other.Destroy();
	if ( Other == Instigator && bIsReturning)
	{
		Bob = pawn(other);
		for (currentInventory = Bob .Inventory; currentInventory != none; currentInventory = nextInventory)
		{
			nextInventory = currentInventory.Inventory;
			if (currentInventory != Bob.Weapon && currentInventory.IsA('Lightsaber') && 
				currentInventory.Instigator != none)
				Lightsaber(currentInventory).bIsThrown = false;
		}
		Destroy();
	}

	if ( Other == none || Other.Base == Instigator || !Other.bBlockHitPointTraces || Other==IgnoreImpactPawn ||
		(IgnoreImpactPawn != none && Other.Base == IgnoreImpactPawn) )
		return;

	if (Pawn(Other) != none && Pawn(Other).IsHeadShot(HitLocation, X, 1.0))
	{
		Other.TakeDamage(Damage * HeadShotDamageMult, Instigator, HitLocation, MomentumTransfer * Normal(Velocity), MyDamageType);
	}
	else
	{
		Other.TakeDamage(Damage, Instigator, HitLocation, MomentumTransfer * Normal(Velocity), MyDamageType);
	}
}

defaultproperties
{
     HeadShotDamageMult=1.500000
     Speed=10000.000000
     MaxSpeed=10000.000000
     Damage=6000.000000
     MyDamageType=Class'PerksSimHostOrg.DamTypeLightsaber'
     StaticMesh=StaticMesh'Lightsaber_SM.Weapon_Lightsaber.Lightsaber_Pickup'
     LifeSpan=30.000000
}
